package ch8.ex11;

public class Swapper {
	public static void main(String... args){
		Apply.process(new SwaperAdapter(), "1234");
		Apply.process(new SwaperAdapter(), "abcde");
	}
}

class CharacterPairSwapper{
	static String swap(String s){
		StringBuilder sb = new StringBuilder(s);
		for (int i = 0; i < sb.length() - 1; i+=2) {
			char ch1 = sb.charAt(i);
			char ch2 = sb.charAt(i + 1);
			
			sb.setCharAt(i, ch2);
			sb.setCharAt(i + 1, ch1);
		}
		return sb.toString();
	}
}

class SwaperAdapter implements Processor{

	public String name() {
		
		return CharacterPairSwapper.class.getSimpleName();
	}

	public Object process(Object input) {

		return CharacterPairSwapper.swap((String)input);
	}
}